package com.elvin.wx.controller;


import com.elvin.wx.beans.UserOrganize;
import com.elvin.wx.service.UserOrganizeService;
import com.elvin.wx.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RestController
@RequestMapping("/userOrganizeController")
@Log4j2
@Api("用户组织管理")
@ApiIgnore
//不要了，暂时不显示，防止以后又要
public class UserOrganizeController {

	@Resource
	private UserOrganizeService service;

	@ApiOperation(value = "获取所有人员组织")
	@PostMapping("/queryAll")
	public Result<Object> queryAll() {
		Result<Object> result = new Result<>();
		try {
			List<UserOrganize> selectList = service.selectList(null);
			result.success(selectList);
		} catch (Exception e) {
			log.debug(e.getMessage());
			result.fail(null, e.getMessage());
		}
		return result;
	}

	@ApiOperation(value = "新增人员组织")
	@PostMapping("/insert")
	public Result<Object> insert(@RequestBody UserOrganize entity) {
		Result<Object> result = new Result<>();
		try {
			service.insert(entity);
			result.success(entity, "新增成功");
		} catch (Exception e) {
			log.debug(e.getMessage());
			result.fail(null, e.getMessage());
		}
		return result;
	}

	@ApiOperation(value = "修改人员组织")
	@PostMapping("/update")
	public Result<Object> update(@RequestBody UserOrganize entity) {
		Result<Object> result = new Result<>();
		try {
			service.updateById(entity);
			result.success("修改成功");
		} catch (Exception e) {
			log.debug(e.getMessage());
			result.fail(null, e.getMessage());
		}
		return result;
	}

	@ApiOperation(value = "删除人员组织")
	@PostMapping("/delete")
	public Result<Object> delete(@ApiParam("id") @RequestParam("id") Integer id) {
		Result<Object> result = new Result<>();
		try {
			service.deleteById(id);
			result.success("删除成功");
		} catch (Exception e) {
			log.debug(e.getMessage());
			result.fail(null, e.getMessage());
		}
		return result;
	}

	@ApiOperation(value = "根据ID获取人员组织")
	@PostMapping("/getById")
	public Result<Object> getById(@ApiParam("id") @RequestParam("id") Integer id) {
		Result<Object> result = new Result<>();
		try {
			UserOrganize entity = new UserOrganize();
			entity.setId(id);
			entity = service.selectById(entity);
			result.success(entity);
		} catch (Exception e) {
			log.debug(e.getMessage());
			result.fail(null, e.getMessage());
		}
		return result;
	}
}

